package com.eastfair.home.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.annotation.annotation.security.PreAuth;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.home.service.HomeServiceBorrowReturnService;
import com.eastfair.venueservice.dto.ServiceBorrowReturnDTO;
import com.eastfair.venueservice.vo.ServiceBorrowReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * <p>
 * 前端控制器
 * 借用归还记录
 * </p>
 *
 * @author linan
 * @date 2022-09-19
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/serviceBorrowReturn")
@Api(value = "ServiceBorrowReturn", tags = "借用归还记录")
public class ServiceBorrowReturnController {

    @Resource
    private HomeServiceBorrowReturnService homeServiceBorrowReturnService;

    /**
     * 分页查询借还记录VO列表.
     *
     * @param pageParams the page params
     * @return the r
     */
    @ApiOperation("分页查询借还记录VO列表")
    @PostMapping("/query/serviceBorrowReturn")
    public R<Page<ServiceBorrowReturnVO>> queryServiceBorrowReturn(@RequestBody PageParams<ServiceBorrowReturnDTO> pageParams) {
        log.info("queryServiceBorrowReturn - 分页查询借还记录VO列表, pageParams={}", pageParams);
        Page<ServiceBorrowReturnVO> page = homeServiceBorrowReturnService.queryServiceBorrowReturn(pageParams);
        return R.success(page);
    }

    /**
     * ID获取借还记录.
     *
     * @param id the id
     * @return the by id
     */
    @ApiOperation("ID获取借还记录")
    @GetMapping("/get/{id}")
    public R<ServiceBorrowReturnVO> getById(@PathVariable("id") Long id) {
        log.info("getById - ID获取借还记录, id={}", id);
        return R.successDef(homeServiceBorrowReturnService.getById(id));
    }

    /**
     * 借用服务.
     *
     * @param serviceBorrowReturnDTO the service borrow return dto
     * @return the r
     */
    @ApiOperation("借用服务")
    @SysLog("借用服务")
    @PostMapping("/borrow")
    public R<Boolean> borrow(@RequestBody ServiceBorrowReturnDTO serviceBorrowReturnDTO) {
        log.info("borrow - 借用服务, serviceBorrowReturnDTO={}", serviceBorrowReturnDTO);
        return R.successDef(homeServiceBorrowReturnService.borrow(serviceBorrowReturnDTO));
    }

    /**
     * 归还服务.
     *
     * @param serviceBorrowReturnDTO the service borrow return dto
     * @return the r
     */
    @ApiOperation("归还服务")
    @SysLog("归还服务")
    @PostMapping("/return")
    public R<Boolean> returnService(@RequestBody ServiceBorrowReturnDTO serviceBorrowReturnDTO) {
        log.info("returnService - 归还服务, serviceBorrowReturnDTO={}", serviceBorrowReturnDTO);
        return R.successDef(homeServiceBorrowReturnService.returnService(serviceBorrowReturnDTO));
    }
}
